BaseCard   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 22
dl 0
loc 27
rs 10
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A buildSections 0 2 1
A createMessage 0 3 1
A create 0 2 1
A createCardWithId 0 6 1
A addSectionWidget 0 3 1
1
import {chat_v1 as chatV1} from '@googleapis/chat';
2
3
interface Card {
4
  buildHeader?(): void;
5
6
  buildSections(): void;
7
8
  buildButtons?(): void;
9
10
  buildFooter?(): void;
11
12
  create(): chatV1.Schema$GoogleAppsCardV1Card;
13
14
  createCardWithId(): chatV1.Schema$CardWithId;
15
16
  createMessage(): chatV1.Schema$Message;
17
}
18
19
export default abstract class BaseCard implements Card {
20
  protected id: string = 'cardId';
21
  private _content: chatV1.Schema$GoogleAppsCardV1Section[] = [];
22
23
  protected card: chatV1.Schema$GoogleAppsCardV1Card = {
24
    sections: this._content,
25
  };
26
27
  protected addSectionWidget(widget: chatV1.Schema$GoogleAppsCardV1Widget) {
28
    this.card.sections!.push({widgets: [widget]});
29
  }
30
31
  abstract buildSections(): void;
32
33
  abstract create(): chatV1.Schema$GoogleAppsCardV1Card;
34
35
36
  createCardWithId(): chatV1.Schema$CardWithId {
37
    return {
38
      'cardId': this.id,
39
      'card': this.create(),
40
    };
41
  }
42
43
  createMessage(): chatV1.Schema$Message {
44
    return {cardsV2: [this.createCardWithId()]};
45
  }
46
}
47